/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.speakglobe.security.service;

import com.speakglobe.security.dao.UserDao;


import com.speakglobe.security.model.User;

import java.util.Date;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author ronnie
 */
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class UserDetailsServiceImpl implements UserDetailsService {
	
	private UserDao userDao;

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
    public User getUser(int userID) {
		return userDao.get(userID);
    }

    @Override
    public User getUserByEmail(String emailAddress) {
    	return userDao.getUserByEmail(emailAddress);
    }

    @Override
    public void save(User user) {
    	user.setCreated(new Date());
        userDao.saveUser(user);
    }

    @Override
    public User loadDBUser(String username, String password, String site, String domain) {
    	return userDao.get(username, password, site, domain);
    }

    @Override
    public List<User> getAllUsers() {
    	return userDao.getAllUsers();
    }

    @Override
    public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException, DataAccessException {
    	return null;
    }
    
}
